from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, BooleanField, PasswordField
from wtforms.validators import DataRequired, Length, Email, Regexp, EqualTo
from wtforms import ValidationError

from ..models import User

class NewTypeForm(FlaskForm):
    """新增字典类别窗体"""
    name = StringField('字段值', validators=[DataRequired(), Length(1, 30)])           # 字典字段值
    isUse = BooleanField('使用状态', validators=[DataRequired()])                       # 是否在用
    submit = SubmitField('提交')

class NewCodeForm(FlaskForm):
    """新增字典编码窗体"""
    fid = StringField('父id', validators=[DataRequired()])                            # 父类id
    name = StringField('字段值', validators=[DataRequired(), Length(1, 30)])           # 字典字段值
    isUse = BooleanField('使用状态', validators=[DataRequired()])                       # 是否在用
    submit = SubmitField('提交')


class EditUserForm(FlaskForm):
    """编辑用户窗体（角色、是否激活）"""
    name = StringField('姓名', validators=[DataRequired(), Length(1, 30)])        # 用户真实姓名，不可修改
    email = StringField('电子信箱', validators=[DataRequired(), Length(1, 254), Email(message='电子邮箱格式不正确。')])   # 用户电子信箱，需要保持唯一
    username = StringField('用户账号', validators=[DataRequired(), Length(1, 20), Regexp('^[a-zA-Z0-9]*$', message='用户账号只包含字母和数字。')])  # 用户账号，需要保持唯一
    role = StringField('角色', validators=[DataRequired()])            # 用户角色
    active = BooleanField('用户激活', validators=[DataRequired()])     # 用户是否激活
    submit = SubmitField('确定提交')


class TestForm(FlaskForm):
    """实验窗体"""
    pass